1467A - Wizard of Orz - CodeForces Solution


constructive algorithms greedy math *900

Please click on ads to support us..

Python Code:

import math
for i in range(int(input())):
    n=int(input())
    a="989"
    s="0123456789"
    if(n<4):
        if(n==1):
            print(9)
        elif(n==2):
            print(98)
        elif(n==3):
            print(989)
    else:
        n=n-3
        print(a+math.floor(n/10)*s+s[:n%10])

C++ Code:

#include<bits/stdc++.h>

using namespace std;



#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mod 1000000007
#define mod1 1000000007
#define INF 1e18
#define endl "\n"
#define pb push_back
#define ppb pop_back
#define ff first
#define ss second
#define PI 3.141592653589793238462
#define set_bits __builtin_popcountll
#define all(x) (x).begin(), (x).end()
#define MAXN 100005

typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
  
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
  
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif

void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

//push kardo lekin answer update nhi karn to hamesha jo pq ka top me hoga
//wo agar first time hai to shortest hi hoga guarantee se

// //Union Find Algorithm Almost O(1) for reasonable size N. O(log*N) to be precise


void solve(){
	ll n;
	cin>>n;
	if(n==1)
	{
		cout<<9<<endl;
		return;
	}
	if(n==2)
	{
		cout<<98<<endl;
		return;
	}
	cout<<98;
	ll v=9;
	for(int i=0;i<n-2;i++)
	{
		cout<<v;
		v++;
		if(v==10)
		{
			v=0;
		}
	}
	cout<<endl;
}

int main() {
#ifndef ONLINE_JUDGE
	 freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
#endif
    fastio();
    int t;
    t=1;
    cin>>t;
	while(t--)
	{
		debug(t);
		solve();
	}
}


Comments

Submit
0 Comments
More Questions

465A - inc ARG
1260A - Heating
1740D - Knowledge Cards
1028A - Find Square
1370B - GCD Compression
888D - Almost Identity Permutations
1106C - Lunar New Year and Number Division
849B - Tell Your World
1650E - Rescheduling the Exam
899C - Dividing the numbers
1023C - Bracket Subsequence
1579D - Productive Meeting
1749E - Cactus Wall
1682C - LIS or Reverse LIS
578A - A Problem about Polyline
1038E - Maximum Matching
1141C - Polycarp Restores Permutation
1685A - Circular Local MiniMax
432B - Football Kit
10C - Digital Root
743B - Chloe and the sequence
909D - Colorful Points
1283C - Friends and Gifts
605B - Lazy Student
1687B - Railway System
61D - Eternal Victory
588B - Duff in Love
12C - Fruits
447B - DZY Loves Strings
325A - Square and Rectangles